package com.lyf.scm.plan.domain.repository;

import com.lyf.scm.plan.api.dto.RoleAuthorityAreaDTO;
import com.lyf.scm.plan.domain.convertor.RoleAuthorityAreaConvertor;
import com.lyf.scm.plan.insfrastructure.db.mapper.RoleAuthorityAreaMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * description:
 *
 * @author: haodong
 * @data: 2020/9/2 15:17
 */
@Service
public class RoleAuthorityAreaRepository {

    @Resource
    private RoleAuthorityAreaMapper roleAuthorityAreaMapper;

    @Resource
    private RoleAuthorityAreaConvertor roleAuthorityAreaConvertor;

    /**
     * 根据用户获取权限范围信息
     * @param userId
     * @return
     */
    public List<RoleAuthorityAreaDTO> listByUserId(Long userId) {
        return roleAuthorityAreaConvertor.doToDTO(roleAuthorityAreaMapper.listByUserId(userId));
    }

    /**
     * 根据权限id查询当前等级下的所有权限范围信息
     * @param roleId
     * @return
     */
    public List<RoleAuthorityAreaDTO> listByRoleId(Long roleId) {
        return roleAuthorityAreaConvertor.doToDTO(roleAuthorityAreaMapper.listByRoleId(roleId));
    }

    /**
     * 根据当前用户查询属于当前用户下级的权限信息
     * @param userId
     * @return
     */
    public List<RoleAuthorityAreaDTO> listByParentUser(Long userId) {
        return roleAuthorityAreaConvertor.doToDTO(roleAuthorityAreaMapper.listByParentUser(userId));
    }
}
